<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<%@ page import="java.sql.*, java.util.*, support.*" %>
<%@page import="support.*, java.util.*" %>
<%@page import="support.*, java.util.*, java.sql.*, javax.sql.*" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %> 
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>
<%@ page import="java.sql.*, java.util.*, support.*" %>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Applications Page</title>
</head>
<body>

<CENTER>
<h1> Graduate School Application </h1>
<h2> Chairs -- Applications Page </h2>
</CENTER>

<head>
<script type="text/javascript">

	
	function toggle(value) {
		//var divs =   document.getElementByTagNames('div');
		var oDiv = document.getElementById('fxm')
		var oBtn = document.getElementById(value)
		
		if (oBtn.value=='Show Application') {
			oDiv.style.display = 'block'
			oBtn.value='Hide Application'
			


		} else {
			oDiv.style.display = 'none'
			oBtn.value='Show Application'
		}
	}

	function showAppInfo(str)
	{ 
		var xmlHttp;
	
		xmlHttp=new XMLHttpRequest();
		if (xmlHttp==null)
		  {
		  alert ("Your browser does not support AJAX!");
		  return;
		  }
		var url="/phase6/login/admins/applications-ajax.jsp";
		url=url+"?username="+str;
		url=url+"&sid="+Math.random();
		
		xmlHttp.onreadystatechange=function()
		{ 
			if (xmlHttp.readyState==4)
			{	
				var xmlDoc = document.getElementById("fxm");
				xmlDoc.innerHTML = xmlHttp.responseText ;
			}
		}
		xmlHttp.open("GET",url,true);
		xmlHttp.send(null);
	}


	function GetXmlHttpObject()
	{
	var xmlHttp=null;
	try
	  {
	  // Firefox, Opera 8.0+, Safari
	  xmlHttp=new XMLHttpRequest();
	  }
	catch (e)
	  {
	  // Internet Explorer
	  try
	    {
	    xmlHttp=new ActiveXObject("Msxml2.XMLHTTP");
	    }
	  catch (e)
	    {
	    xmlHttp=new ActiveXObject("Microsoft.XMLHTTP");
	    }
	  }
	return xmlHttp;
	}

	</script>
	</head>

<%
	int i =0;
%>
<logic:iterate id="nameId" name="adminAnaform" property="names" >
<span style="padding-left:10px"> 
<bean:write name="nameId" property="fname"/> 
</span>
<span style="padding-left:10px"> 
<bean:write name="nameId" property="mname"/> 
</span>
<span style="padding-left:10px"> 
<bean:write name="nameId" property="lname"/> 
</span>
<span style="padding-left:10px"> 
<bean:write name="nameId" property="avg"/> 
</span>
<span style="padding-left:10px"> 
<bean:write name="nameId" property="status"/> 
</span>

<span style="padding-left:5px"> 
<logic:equal name="nameId" property="status" value="Pending">
<bean:define id="username" name="nameId" property="username" />
<% System.out.println("REACHED"); %>

<html:form action="/changeStatus">
<input type="hidden" value='<%=(String) username %>' name="whichapp">
<% String uname = (String) username;  System.out.println("***" + uname);%>
<input type="submit" value="Accept" name="whatstatus">
<input type="submit" value="Reject" name="whatstatus">
    
</html:form>

<form action="">
<input type="hidden" value='<%=(String) username %>' name="whichapp">
<input type=button value='Show Application' onclick='toggle("<%= i %>"); showAppInfo("<%= (String) username %>");' id='<%= i %>'">

</form>

</logic:equal>

<logic:equal name="nameId" property="status" value="Accepted">
<bean:define id="username" name="nameId" property="username" />

<html:form action="/changeStatus">
<input type="hidden" value='<%=(String) username %>' name="whichapp">
<input type="submit" value="Reject" name="whatstatus">
<input type="submit" value="Cancel Decision" name="whatstatus">
</html:form>

<form action="">
<input type="hidden" value='<%=(String) username %>' name="whichapp">
<input type=button value='Show Application' onclick='toggle("<%= i %>"); showAppInfo("<%= (String) username %>");' id='<%= i %>'">

</form>

</logic:equal>

<logic:equal name="nameId" property="status" value="Rejected">
<bean:define id="username" name="nameId" property="username" />
  
<html:form action="/changeStatus">
<input type="hidden" value='<%=(String) username %>' name="whichapp">
<input type="submit" value="Accept" name="whatstatus">
<input type="submit" value="Cancel Decision" name="whatstatus">
</html:form>

<form action="">
<input type="hidden" value='<%=(String) username %>' name="whichapp">
<input type=button value='Show Application' onclick='toggle("<%= i %>"); showAppInfo("<%= (String) username %>");' id='<%= i %>'">

</form>

</logic:equal>
</span>


<p>
<%i++;%>
</logic:iterate>

</body>

    <br>
    <br>
    <div id='fxm'> 

    </div>
	
	<body>

<br>
<br>
<br>
<html:form action="/Logoff">
<html:submit value="Logoff"/>
</html:form>


</body>
</html>


